package com.thesis.utils;

import java.util.LinkedList;

public class Utils {
	
	public static int max(int[] array) {
		int max = array[0];
		for (int i = 0; i < array.length; i++) {
			if (max < array[i])
				max = array[i];
		}
		return max;
	}
	
	public static int positionOfMax(int[] array) {
		int max = array[0];
		int position = 0;
		for (int i = 0; i < array.length; i++) {
			if (max < array[i])
			{	
				max = array[i];
				position = i;
			}
		}
		return position;
	}
	
	
	//=====ISIN
	public static boolean isInArray(int[] array, int key) {
		for (int c : array) {
			if (c == key)
				return true;
		}
		return false;
	}
	
	public static boolean isInLinkedList(LinkedList<Character> list, int key)
	{
		for (Character char1 : list) {
			if (((int)char1)==key)
				return true;
		}
		return false;
	}
	
//	final static public boolean isInArray(char[] array, char key)
//	{
//		for (int i = 0; i < array.length; i++) {
//			if (array[i]==key)
//				return true;
//		}
//		return false;
//	}
//	
//	final static public boolean isInArray(int[] array, char key)
//	{
//		for (int i = 0; i < array.length; i++) {
//			if (array[i]==key)
//				return true;
//		}
//		return false;
//	}

	
	//=====TOSTRING
	public static String arrayToString(int[] array) {
		String temp = "";
		for (int i = 0; i < array.length; i++) {
			temp += array[i] + " ";
		}
		return temp;
	}
	
	public static String arrayToString(short[] array) {
		String temp = "";
		for (int i = 0; i < array.length; i++) {
			temp += (int)array[i] + " ";
		}
		return temp;
	}
	
	public static String linkedListToString(LinkedList<Character> list)
	{
		String temp = "";
		for (int i = 0; i < list.size(); i++) {
			temp+= (int) list.get(i) + " ";
		}
		return temp;
	}
	

	
	public static int[] findAllMaxInArray(int array[]) {
		int count = 0;
		int key = max(array);

		for (int i = 0; i < array.length; i++) {
			if (array[i] == key)
				++count;
		}
		int[] result = new int[count];

		for (int i = 0; i < array.length; i++) {
			if (array[i] == key)
				result[--count] = i;
		}
		return result;
	}
	
	
	public static void removeDuplicate(LinkedList<Character> list)
	{
		if (list.size()==0)
			return;
		char key=list.getFirst();
		for (Character character : list) {
			if(character!=key)
				return;
		}
		list.clear();
		list.add(key);
		return;
	}
	
	
	
}
